import 'package:animal/constant/color.dart';
import 'package:animal/constant/font.dart';
import 'package:animal/item/message_list_item.dart';
import 'package:animal/socket/type_model.dart';
import 'package:animal/ui/friend/model/friend_model.dart';
import 'package:animal/ui/message/controller/message_list_controller.dart';
import 'package:animal/ui/message/page/message_detaile_page.dart';
import 'package:animal/utils/marquee_text.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:animal/widgets/appbar_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';

///消息——消息列表
class MessageListPage extends StatelessWidget {
  const MessageListPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final controller = Get.put(MessageListController());
    return Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBarWidget.defaultAppBar(
            backgroundColor: Colors.white,
            automaticallyImplyLeading: false,
            appBarHeight: ScreenUtil().L(70),
            elevation: 1,
            title: Text("消息",
                style: KFontConstant.myTextStyle(
                  size: 20,
                  bold: true,
                )),
            actions: [
              GFIconButton(
                icon: const Icon(
                  Icons.add,
                  color: Colors.black,
                ),
                onPressed: () {},
                type: GFButtonType.transparent,
              ),
            ],
            bottom: PreferredSize(
              preferredSize: Size(double.infinity, ScreenUtil().L(20)),
              child: Container(
                width: double.infinity,
                color: Colors.blue,
                child: Row(
                  children: [
                    const Icon(Icons.message),
                    Expanded(
                        child: BrnMarqueeText(
                      text: '向左循环滚动显示,系统将于明晚21:00 ~ 22：00进行升级维护向左循环滚动显示,系统将于明晚21:00 ~ 22：00进行升级维护向左循环滚动显示,系统将于明晚21:00 ~ 22：00进行升级维护',
                      textStyle: KFontConstant.myTextStyle(
                        size: 10,
                        color: Colors.white,
                      ),
                      height: ScreenUtil().L(20),
                    ))
                  ],
                ),
              ),
            )),
        body: Column(
          children: [
            searchWidget(),
            Expanded(
              child: EasyRefresh(
                  header: PhoenixHeader(),
                  footer: PhoenixFooter(),
                  controller: controller.refreshController,
                  onRefresh: () async {
                    controller.getMessageList();
                  },
                  onLoad: () async {
                    debugPrint("刷新结束");
                  },
                  child: ListView.builder(
                      shrinkWrap: true,
                      itemCount: 20,
                      physics: const NeverScrollableScrollPhysics(),
                      itemBuilder: (context, index) {
                        return InkWell(onTap: () => Get.to(MessageDetailPage(friendModel: UserModel())), child: const MessageListItem());
                      })),
            )
          ],
        ));
  }

  ///搜索Widget
  static Widget searchWidget() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: ScreenUtil().L(30), vertical: ScreenUtil().L(10)),
      padding: EdgeInsets.symmetric(horizontal: ScreenUtil().L(15)),
      height: ScreenUtil().L(35),
      alignment: Alignment.center,
      decoration: BoxDecoration(color: const Color(0XFFF6F6F6), borderRadius: BorderRadius.circular(ScreenUtil().L(40))),
      child: TextField(
        style: KFontConstant.myTextStyle(size: 16),
        decoration: InputDecoration(
            prefixIcon: Image.asset("icons/icon_search.png", width: ScreenUtil().L(18)),
            //添加内部左边图标
            contentPadding: EdgeInsets.only(top: ScreenUtil().L(3), left: ScreenUtil().L(10)),
            prefixIconConstraints: const BoxConstraints(
                //添加内部图标之后，图标和文字会有间距，实现这个方法，不用写任何参数即可解决
                ),
            isCollapsed: true,
            hintText: "搜索",
            hintStyle: KFontConstant.myTextStyle(size: 16, color: const Color(0XFFBFC4CC)),
            border: InputBorder.none),
      ),
    );
  }
}
